import util from '../../utils/util.js'

Component({
  /**
   * 组件的属性列表
   */
  properties: {
    limit:Number,
    height:Number,
    status:{
      type:String,
      value:'',
      observer(newVal){
        this.setData({
          orderList:[]
        })
        this.orderRequest(newVal)
      }
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    orderList:[],
    page:0,
    noMore:false,
    counts:0
  },
   // 在组件实例进入页面节点树时执行
   attached() {
    this.orderRequest()
  },

  /**
   * 组件的方法列表
   */
  methods: {
    orderRequest(status = '',page = 1 ) {
      const url = util.api.orders;
      const method = 'GET';
      const data = {
        token: util.token,
        status: status,
        page: page,
        limit: 6
      }
      if (page == 1) {
        this.setData({
          orderList: []
        })
      }
      this.setData({
        noMore: false
      })
      wx.showNavigationBarLoading()
      util.sendRequest(url, method, data)
        .then((res => {
            const item=res.data
            const moneyAmount = item.moneyAmount
            const payMoneyAmount = item.payMoneyAmount
            const counts=item.counts
            let list = this.data.orderList
            let orderList = list.concat(item.list)
            this.setData({
              orderList,
              status,
              page,
              moneyAmount,
              payMoneyAmount,
              counts
            })
            wx.hideNavigationBarLoading()
            if(orderList.length==this.data.counts){
              this.setData({
                noMore: true
              })
            }
          console.log(orderList)
        }))
    },
    //下滑加载更多
  scrollDown() {
    this.data.page++
      this.orderRequest(this.data.status, this.data.page)
  },
  }
})
